<?php
App::uses('Component', 'Controller');
class VideoComponent extends Component {
	
	public function registVideoForNewSubject($data) {
		$this->Video = ClassRegistry::init('Video');
		$this->Video->create();
        return $this->Video->save($data);
	}
	
	public function getMainVideo($subId){
		$this->Video = ClassRegistry::init('Video');
		$video = $this->Video->find('all', array(
			'condition' => array('m_video_sub_id' => $subId,
								 'm_is_main_video' => '1')
		));
        return $video;
	}
	
	public function deleteMainVideo($subId){
		$this->Video = ClassRegistry::init('Video');
		return $this->Video->deleteAll(array('Video.m_video_sub_id' => $subId,
										'Video.m_is_main_video' => '1'), false);
	}
	
	public function deleteAllBySubId($subId){
		$this->Video = ClassRegistry::init('Video');
		return $this->Video->deleteAll(array('Video.m_video_sub_id' => $subId), false);
	}
	
}